package com.itheima.dao;

import com.github.pagehelper.Page;
import com.itheima.pojo.CheckGroup;
import com.itheima.pojo.Member;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;

/**
 * @author xiaycbstart
 * @create 2019 12 27 14:54
 */
public interface MemberDao {
    @Select("select * from t_member where phoneNumber = #{telephone}")
    Member findByPhoneNumber(String telephone);

    @Insert("insert into t_member values(null,#{fileNumber},#{name},#{sex},#{idCard},#{phoneNumber},#{regTime},#{password},#{email},#{birthday},#{remark})")
    @Options(useGeneratedKeys = true, keyColumn = "id")
    void add(Member member);

    @Select("select count(*) from t_member where regTime <= #{regTime}")
    Integer findMemberCountBeforeDate(String regTime);

    @Select("select count(id) from t_member where regTime = #{today}")
    Integer findMemberCountByDate(String today);

    @Select("select count(*) from t_member ")
    Integer findMemberTotalCount();

    @Select("select count(id) from t_member where regTime >= #{thisWeekMonday} ")
    Integer findMemberCountAfterDate(String thisWeekMonday);

    @Select("<script>" +
            "select * from t_member\n" +
            "<if test=\"value != null and value.length > 0\">\n" +
            "where fileName like '%' #{value} '%' or name like '%' #{value} '%'" +
            "</if>" +
            "</script>")
    Page<CheckGroup> pageQuery(String value);

    @Delete("delete from t_member where id =#{id}")
    void deleteById(int id);
}
